
# 异常的finally
"""
finally : 只有加了此关键字 ，无论什么情况，finally内部的代码块都被执行
"""


def read_file(file_name):

    f = None
    try:
        f = open(file_name)
        result = f.read()
        return result
    except FileNotFoundError as e:
        print("没有找到文件，请检查文件路径是否正确",e)
    except UnicodeDecodeError as e:
        print("读取文件编码异常",e)
    except Exception as e:
        print("未知异常")

    finally:
        print("=====")
        if f:
            f.close()


if __name__ == '__main__':
    print(read_file('a.txt'))